#!/bin/bash

set -e
set -o pipefail

SED="$1"
shift
OUTPUT=syscalls.h
SYSCALL_INCLUDES="
#include <sys/syscall.h>
"

trap 'rm -f $OUTPUT $OUTPUT.deps' ERR

"$@" -MD -MF "$OUTPUT.deps" <<< "$SYSCALL_INCLUDES" -dM -E - \
	| "$SED" -n -e 's/^#define __NR_\([^ ]*\).*$/UL_SYSCALL("\1", __NR_\1)/p' \
	| sort \
	> "$OUTPUT"
